<template>
  <div class="refund">
    <el-card>
      <h2>临时账户退款</h2>
      <el-form :model="form">
        <el-form-item label="退款金额">
          <el-input v-model="form.amount" type="number" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onRefund">退款</el-button>
        </el-form-item>
      </el-form>
      <el-alert v-if="msg" :title="msg" type="success" show-icon></el-alert>
    </el-card>
  </div>
</template>
<script>
import api from '@/api';
export default {
  data() {
    return { form: { amount: '' }, msg: '', loading: false };
  },
  methods: {
    async onRefund() {
      if (!this.form.amount || this.form.amount <= 0) {
        this.msg = '请输入有效金额';
        return;
      }
      this.loading = true;
      try {
        await api.post('/user/refund', { amount: this.form.amount });
        this.msg = '退款成功！';
        this.form.amount = '';
      } catch (e) {
        this.msg = '退款失败';
      }
      this.loading = false;
    }
  }
};
</script>
<style scoped>
.refund { max-width: 400px; margin: 40px auto; }
</style>
